<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function calc(flag){
            var num=document.getElementById("num");//获取DOM对象
            var val=num.value*1;
            if(flag=="+"){
                val++;
            }else{
                if(val>0){
                    val--;
                }else{
                    alert("你不能再减了哇！！！");
                }

            }
            num.value=val;
        }
    </script>
</head>
<body>
    <input type="button" value="-" onclick="calc('-')">
    <input type="text" value="0" id="num">
    <input type="button" value="+" onclick="calc('+')">
</body>
</html>